<?php
$className = "Users";
/* 
 * All operations concerning multiple users or
 * users in general are to be handled by the Users class.
 *
 */
class Users {
    private $db = null;

    /**
     * The minimum constructor for Users expects at least a Database object.
     * @param Database $db
     */
    public function __construct($db) {
        $this->db = $db;
    }

    /**
     * Returns an array containing User objects of all users that are administrators.
     * @return User[] or boolean (false) if none exist
     */
    public function getAdmins() {
        $sql = "SELECT u.*
                FROM
                Users u INNER JOIN
                Members m ON m.userID=u.ID INNER JOIN
                Groups g ON g.ID=m.groupID
                WHERE g.name='Administrator'";
        $res = $this->db->getResult($sql);
        if(!$res)
            return(false);
        $admins = array();
        foreach($res AS $usr) {
            $admin = new User($usr['firstName'],$usr['middelNames'],$usr['lastName'],$usr['initials'],$usr['email'],$usr['pass'],$usr['status']);
            $admins[] = $admin;
        }
        return($admins);
    }
}
?>
